package data_structure.math;

/**
 * Created by l19743 on 2021/1/4.
 */
public class MathTest {

    /**
     * 利用二分法算数字x的算数平方根
     */
    public int mySqrt(int x) {
        if (x == 0) return 0;
        int left = 1;
        int right = x;
        while (left < right - 1) {
            int mid = (left + right) >>> 1;
            if ((long) mid * mid > x) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return left;

    }
}
